/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Sablony;

/**
 *
 * @author MartinaHlinková
 */
public class NepritomnostZamestnanca implements Comparable<NepritomnostZamestnanca>{
   private InformacnaStruktura.Den denVTyzdni;
   private InformacnaStruktura.CasBezDatumu odCasu;
   private InformacnaStruktura.CasBezDatumu doCasu;
    
    public NepritomnostZamestnanca(InformacnaStruktura.Den den, InformacnaStruktura.CasBezDatumu odCasu, InformacnaStruktura.CasBezDatumu doCasu){
        this.denVTyzdni = den;
        this.odCasu = odCasu;
        this.doCasu = doCasu;
    }
    
    public InformacnaStruktura.Den getDenNepritomnosti(){
        return this.denVTyzdni;
    }
    
    public InformacnaStruktura.CasBezDatumu getCasOdkedy(){
        return this.odCasu;
    }
    
    public InformacnaStruktura.CasBezDatumu getCasDokedy(){
        return this.doCasu;
    }
    
    public boolean skontrolujSpravnost(){
        if(this.denVTyzdni == null || this.doCasu == null || this.odCasu == null) return false;
        if(this.odCasu.compareTo(this.doCasu) >= 0) return false;
        return true;
    }

    @Override
    public int compareTo(NepritomnostZamestnanca o) {
        if(this.denVTyzdni.compareTo(o.denVTyzdni) != 0){
            return this.denVTyzdni.compareTo(o.denVTyzdni);
        }
        if(this.odCasu.compareTo(o.odCasu) != 0){
            return this.odCasu.compareTo(o.odCasu);
        }
        if(this.doCasu.compareTo(o.doCasu) != 0){
            return this.doCasu.compareTo(o.doCasu);
        }
        return 0;
    }
    
    public boolean equals(Object o){
        if(o == this){
            return true;
        }
        if(o instanceof Sablony.NepritomnostZamestnanca == false){
            return false;
        }
        if( ((NepritomnostZamestnanca) o).getDenNepritomnosti().equals(this.getDenNepritomnosti())){
            if( ((NepritomnostZamestnanca) o).getCasOdkedy().equals(this.getCasOdkedy()))
                if(((NepritomnostZamestnanca) o).getCasDokedy().equals(this.getCasDokedy()))return true;
        }
        return false;
    }
    public boolean majuRovnakeIntervaly(NepritomnostZamestnanca o){
        if(this.denVTyzdni != o.denVTyzdni) return false;
        if(o.getCasOdkedy().equals(this.getCasOdkedy())) return true;
        if(o.getCasDokedy().equals(this.getCasDokedy())) return true;
        if(o.getCasOdkedy().equals(this.getCasDokedy())) return false;
        if(o.getCasDokedy().equals(this.getCasOdkedy())) return false;
        
        if(this.getCasOdkedy().after(o.getCasOdkedy()) && this.getCasOdkedy().before(o.getCasDokedy())){
            return true;
        }
        if(this.getCasDokedy().after(o.getCasOdkedy()) && this.getCasDokedy().before(o.getCasDokedy())){
            return true;
        }
        if(o.getCasOdkedy().after(this.getCasOdkedy()) && o.getCasOdkedy().before(this.getCasDokedy())){
            return true;
        }
        if(o.getCasDokedy().after(this.getCasOdkedy()) && o.getCasDokedy().before(this.getCasDokedy())){
            return true;
        }
            
        return false;
    }
    
    @Override
    public String toString(){
        String navrat = ""+this.denVTyzdni.toString()+" "+this.getCasOdkedy().toString()+" : "+this.getCasDokedy().toString()+" : ";
        return navrat;
    }
}
